package com.example.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.manager.ProductManager;
import com.example.mapper.ProductMapper;
import com.example.model.ProductDO;
import com.example.vo.ProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yinxin
 * @version 1.0
 * @Description:
 * @date 2022/6/1315:56
 */
@Component
@Slf4j
public class ProductManagerImpl implements ProductManager {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<ProductVO> list() {
        List<ProductDO> list = productMapper.selectList(new QueryWrapper<ProductDO>());
        return list.stream().map(o -> beanProcess(o)).collect(Collectors.toList());
    }

    @Override
    public ProductDO findDetailById(Long id) {
        return productMapper.selectById(id);
    }

    private ProductVO beanProcess(ProductDO productDO){
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(productDO,productVO);
        return productVO;
    }

}
